package com.itheima.spring.context;

import com.itheima.spring.beans.BeanFactory;
import com.itheima.spring.beans.BeanPostProcessor;
import com.itheima.spring.beans.PreBuildBeanFactory;

/**
 * 抽象XmlApplicationContext还是AnnotationApplicationContext
 * 无论是XmlApplicationContext还是AnnotationApplicationContext都要
 * 使用BeanFactory和BeanDefinitionRegistry,所以对他们再进行一次抽象
 */
public abstract class AbstractApplicationContext implements ApplicationContext{

    protected BeanFactory beanFactory;

    public AbstractApplicationContext() {
        this.beanFactory = new PreBuildBeanFactory();
    }

    /**
     *
     * @param name 通过beanname获取bean
     * @return
     * @throws Exception
     * @throws Throwable
     */
    @Override
    public Object getBean(String name) throws Exception, Throwable {
        return beanFactory.getBean(name);
    }

    /**
     * //注册bean定义信息到bean工厂
     * @param bpp
     */
    @Override
    public void registerBeanPostProcessor(BeanPostProcessor bpp) {
        beanFactory.registerBeanPostProcessor(bpp);
    }

}
